#!/bin/sh
#copyright @tangxuning

echo "	QA测试快速脚本 v1"
echo ""
echo "请输入执行操作的测试环境分支名称（比如：dev02）："
read -p "请输入分支名称（比如：dev02）：" branch



if [ $branch == shiyang ]
then
	echo "石阳的测试分支"
elif [ $branch == weiqing ]
then
	echo "卫庆的测试分支"
elif [[ $branch =~ ^dev\d* ]]
then
	echo "$branch测试分支"
else
	echo "输入错误，脚本结束"
	exit 
fi
#exit

echo ""
echo "	1.执行队列重启"
echo "	2.同步指定工作区的数据"
echo "	3.执行数据仓库定时同步"
echo "	4.版本付费新手体验礼包、免费体验版过期，试用期到期处理 "
echo "	5.版本付费处理企业人数20人（每小时一次）-A型企业"
echo "	6.版本付费周期发放脚本"
echo ""
read -p "选择输入编号：" kind

if [ $kind == 1 ]
then
	if [ $branch == shiyang   ]
	then		
		sudo su - user_00 -l -c "/data/home/simoyang/web_v2/app/misc/fifo_queue.sh  batch_restart"
	elif [ $branch == weiqing ]
	then
		sudo su - user_00 -l -c "/data/home/renweiqing/web_v2/app/misc/fifo_queue.sh  batch_restart"
	else
		sudo su - user_00 -l -c "/data/web/huoban_${branch}_v2/app/misc/fifo_queue.sh  batch_restart"
	fi
elif [ $kind == 2 ]
then
	echo "	同步指定工作区的数据"
	read -p "请输入工作区ID：" space_id
	
	if [ $branch == shiyang   ]
	then
		sudo su - user_00 -l -c "/data/home/simoyang/web_v2/app/misc/bi_ctrl.sh  -a trigger_all -s ${space_id}"
	elif [ $branch == weiqing ]
	then
		sudo su - user_00 -l -c "/data/home/renweiqing/web_v2/app/misc/bi_ctrl.sh  -a trigger_all -s ${space_id}"
	else
			sudo su - user_00 -l -c "/data/web/huoban_${branch}_v2/app/misc/bi_ctrl.sh  -a trigger_all -s ${space_id}"
	fi

elif [ $kind == 3 ]
then
	date = `date -d "-1 days" +'%Y-%m-%d %T'`
	echo "	执行数据仓库定时同步"
	if [ $branch == shiyang ]
	then		
		sudo su - user_00 -l -c "/data/home/simoyang/web_v2/app/misc/bi_ctrl.sh -a cron_sync -v '${date}'"
	elif [ $branch == weiqing ]
	then
		sudo su - user_00 -l -c "/data/home/renweiqing/web_v2/app/misc/bi_ctrl.sh -a cron_sync -v '${date}'"
	else
		sudo su - user_00 -l -c "/data/web/huoban_${branch}_v2/app/misc/bi_ctrl.sh -a cron_sync -v '${date}'"
	fi
elif [ $kind == 4 ]
then
	if [ $branch == shiyang   ]
	then
		sudo su - user_00 -l -c "/data/home/simoyang/web_v2/app/backend/command.php -n  cron_handle_gift_expired"
	elif [ $branch == weiqing ]
	then
		sudo su - user_00 -l -c "/data/home/renweiqing/web_v2/app/backend/command.php -n  cron_handle_gift_expired"
	else
			sudo su - user_00 -l -c "/data/web/huoban_${branch}_v2/app/backend/command.php -n  cron_handle_gift_expired"
	fi
elif [ $kind == 5 ]
then
	if [ $branch == shiyang   ]
	then
		sudo su - user_00 -l -c "/data/home/simoyang/web_v2/app/backend/command.php -n  cron_handle_company_resource"
	elif [ $branch == weiqing ]
	then
		sudo su - user_00 -l -c "/data/home/renweiqing/web_v2/app/backend/command.php -n  cron_handle_company_resource"
	else
			sudo su - user_00 -l -c "/data/web/huoban_${branch}_v2/app/backend/command.php -n  cron_handle_company_resource"
	fi
elif [ $kind == 6 ]
then
	echo "	版本付费周期发放脚本"
	read -p "请输入企业ID：" company_id
	echo ""
	read -p "请输入脚本执行时间（比如：2020-04-05）：" t_time
	if [ $branch == shiyang   ]
	then
		sudo su - user_00 -l -c "/data/home/simoyang/web_v2/app/backend/command.php -n cron_init_module_price_add_capacity -t ${t_time}  -c ${company_id}"
	elif [ $branch == weiqing ]
	then
		sudo su - user_00 -l -c "/data/home/renweiqing/web_v2/app/backend/command.php -n cron_init_module_price_add_capacity -t ${t_time}  -c ${company_id}"
	else
			sudo su - user_00 -l -c "/data/web/huoban_${branch}_v2/app/backend/command.php -n cron_init_module_price_add_capacity -t ${t_time}  -c ${company_id}"
	fi
else
	echo "输入错误，脚本结束"
fi
